home *** CD-ROM | disk | FTP | other *** search
- Path: realtime.net!usenet
- From: rflores@bga.com (Roberto Flores)
- Newsgroups: comp.lang.c++
- Subject: Need Help Creating DLL with Return Arguments
- Date: 13 Mar 1996 23:13:57 GMT
- Organization: Real/Time Communications Internet customer posting
- Message-ID: <4i7krl$g9i@news2.realtime.net>
- NNTP-Posting-Host: jake-4m.aip.realtime.net
- Mime-Version: 1.0
- X-RTcode: 4568691f31b59675d94756bb
- X-Newsreader: WinVN 0.93.11
-
- I am using MSVC++ 1.5 on Windows 3.1 to create a DLL that receives a DOS
- environment variable, uses getenv( "<variable>" ) and returns the
- value back. When I try to use the DLL in a 'C++' program, it GPFs when
- it attempts to call the function in the DLL created. Is there somthing I
- am doing wrong or not doing? Please help. I am using the following code
- to create the DLL (following the DLL code, is the code used to try to
- use it):
-
- #include <stdlib.h>
- #include <windows.h>
-
- int FAR PASCAL LibMain(HINSTANCE hInstance,WORD wDataSeg,WORD wHeapSize,LPSTR lpszCmdLine)
- {
- if (wHeapSize > 0)
- UnlockData(0);
- return 1;
- }
-
- int FAR PASCAL GetEnvironmentVar( char *envar, char *rtn_value )
- {
- rtn_value = getenv( envar );
- return(0);
- }
-
- void FAR PASCAL WEP(int nParameter)
- {
- return;
- }
- //End of DLL code
-
- Special thanks to Pete Grant for helping with the following code. The
- code is the C++ program attempting to use the GETENVAR.DLL, I have
- created. Code follows:
-
- #include <stdio.h>
- #include <windows.h>
-
- int main ()
- {
- void prtuser(char *text1);
-
- prtuser("USERID");
- return(0);
- }
-
- void prtuser(text1)
- char *text1;
- {
- extern int _export _far _pascal GetEnvironmentVar( char *str1, char *str2);
- char *rtn_envar ="**********";
- char *envar = "**********";
-
- HINSTANCE hinstGetEnVar;
- typedef BOOL (FAR *mycallback) (LPCSTR, LPSTR);
- mycallback lpfnGetEnvironmentVar;
-
- sprintf(envar, text1);
- printf(">%s<: ", envar);
- hinstGetEnVar = LoadLibrary("GETENVAR.DLL");
-
- if ( hinstGetEnVar > 32 ) {
- lpfnGetEnvironmentVar = (mycallback)GetProcAddress(hinstGetEnVar,"GetEnvironmentVar" );
- if (lpfnGetEnvironmentVar != NULL ) {
- if ( (*lpfnGetEnvironmentVar) (envar, rtn_envar) )
- printf("%s\n", rtn_envar );
- else
- printf("Function Call Failed:\n");
- }
- else
- printf("Find Function Failed\n");
- }
- else {
- printf("LoadLibrary Failed\n");
- }
- FreeLibrary( hinstGetEnVar );
- }
-
-
- Please reply with help to:
-
- rflores@bga.com or Robert.Flores@tpwd.state.tx.us
-
- ...please, please, please, please.
-
- Thanks A Bunch
-
- Roberto Flores
-
-